package anjoyo.android.ADapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
import anjoyo.android.model.MusciModel;
import anjoyo.android.ui.R;
import anjoyo.yl.mp3player.ChoiseAll;

public class DuoXuanAddapter extends BaseAdapter {

	private Context context;
	private  ArrayList<MusciModel> listData;
	
	public DuoXuanAddapter(Context context, ArrayList<MusciModel> listData){
		this.context = context;
		this.listData = listData;
	}
	
	@Override
	public int getCount() {
		return listData.size();
	}

	@Override
	public Object getItem(int position) {
		return listData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {  
			 LayoutInflater mInflater = (LayoutInflater) context   
		                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);   
	           convertView = mInflater.inflate(R.layout.choiseall_listitem,null);      
	           holder = new GridHolder(); 
	            holder.txt1 = (TextView)convertView.findViewById( R.id.ChoiseAll_list_txt1);
	            holder.txt2 = (TextView)convertView.findViewById( R.id.ChoiseAll_list_txt2 );
	            holder.btn1 = (CheckBox)convertView.findViewById(R.id.ChoiseAll_list_check);
	            convertView.setTag(holder);      
	 
	       }else{   
	            holder = (GridHolder) convertView.getTag();      
	     }
		
		
		 holder.txt1.setText(listData.get(position).getMusic_Name());
		 holder.txt2.setText(listData.get(position)
					.getMusic_Path()
					.substring(
							listData.get(position).getMusic_Path()
									.lastIndexOf(".") + 1)
					+ "  " +listData.get(position).getMp3Size());
		 if(ChoiseAll.ChoiseMap.get(position)){
			 holder.btn1.setChecked(true);
		 }else{
			 holder.btn1.setChecked(false);
		 }
		 return convertView;
	}
	
	GridHolder   holder;
	
	
	 private class GridHolder {   
	        TextView txt1;
	        TextView txt2;
	        CheckBox btn1;
	   } 

}
